<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fmtt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set value="${pageContext.request.contextPath}" var="path"></c:set>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <script type="text/javascript" src="/myhouse/static/manager/js/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/myhouse/static/manager/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="/myhouse/static/manager/css/main.css"/>
    <script type="text/javascript" src="/myhouse/static/manager/js/libs/modernizr.min.js"></script>
</head>
<body>
<jsp:include page="/inc/managerHead.jsp"></jsp:include>
<div class="container clearfix">
    <jsp:include page="/inc/managerLeft.jsp"></jsp:include>
    <!--/sidebar-->
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="/myhouse/manager/index">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">增加房屋类型</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                    <table class="search-tab">
                        <tr>
                            <th width="100">增加房屋类型:</th>
                            <td><input class="common-text" name=""  type="text" id="num"></td>
                            <td><input class="btn btn-primary btn2"  value="添加" type="button" id="sss"></td>
                        </tr>
                    </table>
                <span id="nnd"></span>
            </div>
        </div>

        <script type="text/javascript">
            $(function (){
                $("#sss").click(mediatorByName);
            });
            function mediatorByName(){
                var num = $("#num").val()
                if ( num != ""){
                    $.ajax({
                        url:"/myhouse/manager/mag",
                        type:"get",
                        data:{typeName:num},
                        success:function (mes){
                            if(mes == "1"){
                                $.ajax({
                                    url: "/myhouse/manager/MgAdd",
                                    type: "get",
                                    data: {"typeName":num},
                                    success:function (){
                                        location.href="/myhouse/manager/MgAdd"
                                    }
                                })
                            }else {
                                $("#nnd").text("已有该类型");
                                $("#nnd").css("color","red");
                            }
                        }
                    })
                }
            }
        </script>

        <div class="result-wrap">
            <form name="myform" id="myform" method="get">
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th>id</th>
                            <th>用户名</th>
                            <th>操作</th>
                        </tr>
                            <c:forEach items="${requestScope.typeList}" var="type">
                        <tr>
                            <td>${type.id}</td>
                            <td>${type.typeName}</td>
                            <td onclick="sc(this)" style="color: #0a53be">删除</td>
                        </tr>
                            </c:forEach>
                    </table>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript">

        function sc(a){
            var bool = window.confirm("确定删除吗？");
            var id = $(a).parent().find('td:first').text();
            if (bool){
               $.ajax({
                   url:"/myhouse/manager/delete",
                   type:"get",
                   data:{
                       id:id
                   },
                   success:function (mes){
                        location.href="/myhouse/manager/MgAdd";
                   }
               })
            }
        }
    </script>
</div>
</body>
</html>